<?php

namespace app\models;

use app\models\events\UploadEvent;
use Yii;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
/**
 * This is the model class for table "artist".
 *
 * @property integer $id
 * @property string $name
 * @property string $alias
 * @property string $brief_desc
 * @property string $pic_url
 * @property string $trans
 * @property integer $created_at
 * @property integer $updated_at
 */
class Artist extends ActiveRecord
{
    use DropDownListTrait;
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'artist';
    }


    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name', 'alias', 'brief_desc', 'pic_url', 'trans'], 'required'],
            [['name', 'alias'], 'string', 'max' => 50],
            [['brief_desc', 'pic_url', 'trans'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => '名称',
            'alias' => '别名',
            'brief_desc' => '描述',
            'pic_url' => '图片地址',
            'trans' => '翻译',
            'created_at' => '创建时间',
            'updated_at' => '修改时间',
        ];
    }

    public function behaviors()
    {
        return [
            [
                'class' => TimestampBehavior::className(),
                'attributes'=>[
                    ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],
                    ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
                ],
            ],
            [
                'class'=>UploadEvent::className(),
                'changeAttribute'=>'pic_url',
            ]
        ];
    }
}
